var app = getApp()
Page({
  data: {
    result: '',
    money: "",
    year: "",
    active: 3.25,
    show: false,
    key: ''
  },
  onLoad: function(){
    this.getKey()
},
getKey() {
  let that = this
  wx.cloud.callFunction({
    name: 'getKey',
    data: {
      name: 'daikuan'
    }
  }).then(res => {
    console.log(res.result.data[0].key)
    that.setData({
      key: res.result.data[0].key
    })
  })
},

  

  /**
   * 获取用户输入 
   */
  valMoney: function (e) {
    this.setData({
      money: e.detail.value
    })
  },
  valYear: function (e) {
    this.setData({
      year: e.detail.value
    })
  },
  valActive: function (e) {
    this.setData({
      active: e.detail.value
    })
  },
  // 事件处理函数
  onInput: function (e) {
    var that=this
      wx.request({
        url: "https://apis.juhe.cn/fapig/loanCalc/loan?key="+that.data.key+"&money="+that.data.money+"&active=" + that.data.active + "&year=" + that.data.year,
        data: {
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          console.log(res)
          wx.hideLoading();
          if (res.statusCode == 200) {
            that.setData({
              result: res.data.result,
              show: true
            })
          } else {
            that.setData({
              result: '服务器错误！',
              show: false
            })
          }
        },
        fail(res){
          console.log(res)
        }
      })
  },

})
